#include "EquipIcon.h"
#include "../../model/static/StaticItem.h"
#include "EquipIconLoader.h"

EquipIcon::EquipIcon(void)
	:mBg(NULL),mIcon(NULL)
{
}

EquipIcon::~EquipIcon(void)
{
	CC_SAFE_RELEASE(mBg);
	CC_SAFE_RELEASE(mIcon);
}

bool EquipIcon::init()
{
	return true;
}

SEL_MenuHandler EquipIcon::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName )
{
	return NULL;
}

SEL_CCControlHandler EquipIcon::onResolveCCBCCControlSelector( CCObject * pTarget, CCString * pSelectorName )
{
	return NULL;
}

bool EquipIcon::onAssignCCBMemberVariable( CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode )
{
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mBg", CCSprite *, this->mBg);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mIcon", CCSprite *, this->mIcon);
	return false;
}

void EquipIcon::onNodeLoaded( CCNode * pNode, CCNodeLoader * pNodeLoader )
{

}

void EquipIcon::onEnter()
{
	CCNode::onEnter();
}

void EquipIcon::onExit()
{
	CCNode::onExit();
}

void EquipIcon::refresh()
{

}

void EquipIcon::setIcon( int itemID )
{
	mItemID = itemID;
	EquipStatic* equipStatic = StaticItem::getSingletonPtr()->getEquipInfo(itemID);
	mIcon->initWithFile(equipStatic->icon);
}

void EquipIcon::setQuality( int quality )
{
	mQuality = (EquipQuality)quality;
	switch(mQuality)
	{
	case EQUIP_QUALITY_WHITE:
		mBg->initWithFile("sprite/equip_bg_white.png");
		break;
	case EQUIP_QUALITY_BLUE:
		mBg->initWithFile("sprite/equip_bg_blue.png");
		break;
	case EQUIP_QUALITY_YELLOW:
		mBg->initWithFile("sprite/equip_bg_yellow.png");
		break;
	case EQUIP_QUALITY_GOLD:
		mBg->initWithFile("sprite/equip_bg_gold.png");
		break;
	case EQUIP_QUALITY_PURPLE:
		mBg->initWithFile("sprite/equip_bg_purple.png");
		break;
	case EQUIP_QUALITY_ORANGE:
		mBg->initWithFile("sprite/equip_bg_orange.png");
		break;
	}
}

void EquipIcon::setInfo( int itemID, int quality )
{
	setIcon(itemID);
	setQuality(quality);
}

void EquipIcon::setInfo(int itemID)
{
    setIcon(itemID);
    EquipStatic* equipStatic = StaticItem::getSingletonPtr()->getEquipInfo(itemID);
    setQuality(equipStatic->quality);
}

EquipIcon* EquipIcon::create( CCObject* pOwer )
{
	RegisterLoader("EquipIcon", EquipIconLoader::loader());
	return (EquipIcon*)(ReadNode("EquipIcon.ccbi", pOwer));
}
